package com.have.blog.admin.controller;

import com.have.blog.utils.ResultUtils;
import com.have.blog.xo.constant.MessageConstant;
import com.have.blog.xo.constant.SysConstant;
import com.have.blog.xo.service.admin.SystemDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sysDictData")
@Api(value = "字典数据相关接口", tags = {"字典数据相关接口"})
@Slf4j
public class SystemDictDataController {
    @Autowired
    private SystemDictDataService sysDictDataService;

    @ApiOperation(value = "根据字典类型获取字典数据", notes = "根据字典类型获取字典数据", response = String.class)
    @PostMapping("/getListByDictType")
    public String getListByDictType(@RequestParam("dictType") String dictType) {
        if (StringUtils.isEmpty(dictType)) {
            return ResultUtils.result(SysConstant.ERROR, MessageConstant.OPERATION_FAIL);
        }
        return sysDictDataService.getListByDictType(dictType);
    }

    @ApiOperation(value = "根据字典类型数组获取字典数据", notes = "根据字典类型数组获取字典数据", response = String.class)
    @PostMapping("/getListByDictTypeList")
    public String getListByDictTypeList(@RequestBody List<String> dictTypeList) {
        if (dictTypeList.size() <= 0) {
            return ResultUtils.result(SysConstant.ERROR, MessageConstant.OPERATION_FAIL);
        }
        return sysDictDataService.getDataListByDictTypeList(dictTypeList);
    }
}
